﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QL_DTTN.DAL;
using System.Data.SqlClient;
using System.Data;
using System.Runtime.InteropServices;
namespace QL_DTTN.DTO.DTO
{
    public partial  class CongCu 
    {
        public bool GetCongCu()
        {
            if (this.MaCongCu == 0) return false;
            SqlDataProvider dp=new SqlDataProvider();
            SqlDataReader dr = GetObject(this.MaCongCu, dp);
            if (dr == null) return false;
            bool kt = false;
            while (dr.Read())
            {
                if (!Convert.IsDBNull(dr["MaCongCu"])) this.MaCongCu = Convert.ToInt16(dr["MaCongCu"]);
                if (!Convert.IsDBNull(dr["TenCongCu"])) this.TenCongCu = dr["TenCongCu"].ToString();
                kt = true;
            }
            dp.CloseConnection();
            return kt;
        } 
        public bool Them()
        {
            SqlDataProvider dp = new SqlDataProvider();
            string str = String.Format("insert into {0} (TenCongCu) values (@pTenCongCu) select @@IDENTITY", _tableName);
            dp.AddParameter(new SqlParameter("@pTenCongCu", this.TenCongCu));
            object kq = new object();
            bool kt=  dp.RunReturnSQL(str,ref kq,true);
            this.MaCongCu = Convert.ToInt16(kq);
            return kt;
        }
        public bool Xoa()
        { return Xoa(this.MaCongCu);}
        public bool Xoas(List<Int16>lstMaCongCu)
        {
            return Xoas(lstMaCongCu);
        }
    }
}
